package cn.edu.neusoft.practice.Controller;

import io.swagger.annotations.Api;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import cn.edu.neusoft.practice.mapper.DoctorMapper;
import cn.edu.neusoft.practice.po.Doctor;

import com.mysql.cj.xdevapi.Result;

@CrossOrigin
@Api("DoctorControlloer相关的api")
@RestController
public class DoctorController {

	@Autowired
	private DoctorMapper doctorMapper;
	

	@RequestMapping("/getDoctors")
	@ResponseBody
	public List<Doctor>  getDoctors(){
		List<Doctor> list=doctorMapper.selectList(null);
		return list;
	}
	@RequestMapping("/addDoctors")
	@ResponseBody
	public int addDoctors(Doctor doctor){
		SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");//设置日期格式
		String date = df.format(new Date());
		doctor.setDocId(date);
		System.out.println("医生信息"+doctor);
		int insert = doctorMapper.insert(doctor);
		return insert;

	}
	@RequestMapping("/deleteDoctors")
	public int deletedoctor(Doctor doctor){
		return doctorMapper.deleteById(doctor.getDocId());
	}

	@RequestMapping("/updateDoctors")
	public int updateDoctors(Doctor doctor){
		return doctorMapper.updateById(doctor);
	}

	@RequestMapping("/getDoctorsId")
	public List<Doctor>  getDoctorsByDepartId2(Doctor doctor){
		List<Doctor> Doctor = doctorMapper.getDoctorsByDepartId2(doctor);
		return Doctor;
	}
	@RequestMapping("/getDoctorsByDp1")
	public List<Doctor> getDoctorsById(Doctor doctor){
		QueryWrapper<Doctor> Wrapper = new QueryWrapper<Doctor>();
		Wrapper.eq("depart_id1",doctor.getDepartId1());
		List<Doctor> doctors = doctorMapper.selectList(Wrapper);
		return  doctors;
	}
	@GetMapping("/getDoctorsByName")
	public List<Doctor> getDoctorsByName(Doctor doctor){
		QueryWrapper<Doctor> Wrapper = new QueryWrapper<Doctor>();
		Wrapper.eq("doc_id",doctor.getDocId());
		List<Doctor> doctors = doctorMapper.selectList(Wrapper);
		return  doctors;
	}
	//是否推荐
	@GetMapping("/updateRecommend")
	public int updateRecommend(Doctor doctor){
		int i = doctorMapper.updateRecommend(doctor);
		return i;
	}
	//是否推荐展示查询
	@GetMapping("/getDoctorsRecommend")
	public List<Doctor> getDoctorsRecommend(){
		QueryWrapper<Doctor> Wrapper = new QueryWrapper<Doctor>();
		Wrapper.eq("recommend","1");
		List<Doctor> doctors = doctorMapper.selectList(Wrapper);
		return  doctors;
	}

		
	
}